/**
 * Created by liuzengrong on 2019/8/16.
 */
import React from 'react';
import { connect } from 'dva';
import { message } from 'antd';
import StandardModule from '@/components/hyperspace/modules/StandardModule';
import SupplierOrderDetail from './components/SupplierOrderDetail';
import CostList from '../../../components/Business/costList';

let supplierOrderDetail: any = {};
let costList: any = {};

/**
 * 自定义模块
 */
// @ts-ignore
const LocalModule: React.FC = ({ supplierOrder, dispatch }) => (
  <div>
    <StandardModule
      data={supplierOrder.data}
      config={{
        common: {
          formItemOptions: {
            username: {
              rules: [{ required: true, message: '该字段不能为空！' }],
            },
          },
        },
        search: {
          fields: ['orderNo', 'supplierCode', 'companyName'], // 查询条件
          tabs: {
            field: 'status',
            tabItems: [
              {
                title: '全部',
                value: '',
                active: true,
              },
              {
                title: '草稿',
                value: 'TO_AUDIT1',
              },
              {
                title: '待审核',
                value: 'TO_AUDIT',
              },
              {
                title: '审核通过',
                value: 'AUDIT_PASS',
              },
              {
                title: '未采购',
                value: 'AUDIT_FAIL',
              },
              {
                title: '已采购',
                value: 'ONLINE',
              },
              {
                title: '已完成',
                value: 'OFFLINE',
              },
            ],
          }, // 状态栏
        },
        list: {
          url: '/api/supplierOrder/query',
          fields: [
            'id',
            'orderNo',
            'supplierCode',
            'companyName',
            'goodsName',
            'total',
            'status',
            'creator',
            'creatTime',
          ], // 列表字段
          format: {
            username: {
              render: (value: any) => `格式化 - ${value}`,
            },
          },
          extensions: {
            operations: [
              (record: any) => (
                <a
                  onClick={() => {
                    message.info(`扩展操作：${JSON.stringify(record)}`);
                  }}
                >
                  查看
                </a>
              ),
              (record: any) => (
                <a
                  onClick={() => {
                    message.info(`扩展操作：${JSON.stringify(record)}`);
                  }}
                >
                  审核
                </a>
              ),
              (record: any) => (
                <a
                  onClick={() => {
                    message.info(`扩展操作：${JSON.stringify(record)}`);
                  }}
                >
                  已下单
                </a>
              ),
              (record: any) => (
                <a
                  onClick={() => {
                    message.info(`扩展操作：${JSON.stringify(record)}`);
                  }}
                >
                  已完成
                </a>
              ),
              (record: any) => (
                <a
                  onClick={() => {
                    message.info(`扩展操作：${JSON.stringify(record)}`);
                  }}
                >
                  撤销
                </a>
              ),
              (record: any) => (
                <a
                  onClick={() => {
                    costList.handleOpen();
                  }}
                >
                  费用明细
                </a>
              ),
            ],
          },
        },
        add: {
          url: '/api/supplierOrder/create',
          // width: 680, // 非必填，默认680px
          // title: '新建表单', // 非必填，默认`新建`
          fields: [
            'supplierCode',
            'companyName',
            'supplierType',
            'transportType',
            'contactor',
            'contactContent',
            'level',
            'status',
            'begindate',
            'enddate',
            'address',
            'memo',
          ], // 新增表单字段
        },
        update: {
          url: '/api/supplierOrder/update',
          // width: 680, // 非必填，默认680px
          // title: '新建表单', // 非必填，默认`新建`
          fields: [
            'supplierCode',
            'companyName',
            'supplierType',
            'transportType',
            'contactor',
            'contactContent',
            'level',
            'status',
            'begindate',
            'enddate',
            'address',
            'memo',
          ], // 修改表单字段
          primaryKeys: ['id'], // 主键字段列表
        },
        delete: {
          url: '/api/supplierOrder/remove',
          batchDelete: false, // 是否开启批量删除
          fields: ['id'], // 删除依据字段
        },
      }}
      namespace="supplierOrder"
      dispatch={dispatch}
    />
    <SupplierOrderDetail
      wrappedComponentRef={(inst: any) => {
        supplierOrderDetail = inst;
        return supplierOrderDetail;
      }}
      {...supplierOrderDetail}
      visible
    />
    <CostList
      wrappedComponentRef={(inst: any) => {
        costList = inst;
        return costList;
      }}
      {...costList}
    />
  </div>
);

// @ts-ignore
export default connect(({ supplierOrder }) => ({
  supplierOrder,
}))(LocalModule);
